
clear all;
close all;

A = { "gsl_ext_mnewton", ...
      "gsl_steepest_descent", ...
      "gsl_ext_conjgrad_fr_mt", ...
      "gsl_ext_conjgrad_pr_mt", ...
      "gsl_conjugate_fr", ...
      "gsl_conjugate_pr", ...
      "gsl_ext_bfgs_hess_mt", ...
      "gsl_ext_bfgs_mt", ...
      "gsl_ext_bfgs_f", ...
      "gsl_vector_bfgs2", ...
      "gsl_vector_bfgs", ...
      "gsl_ext_lrwwsimplex", ...
      "gsl_nmsimplex" };

A_sets = { [ 4, 8, 9, 10, 12 ], ...
           [ 3, 4, 5, 6 ], ...
           [ 7, 8, 9, 10, 11 ], ...
           [ 12, 13 ], ...
           [ 1 ] };

A_titles = cell(length(A), 1);
for ai = 1:length(A)
  A_titles{ai} = strrep(A{ai}, '_', '\_');
endfor

N = 10:10:300;

TF = GSLpp_testfunctions();
tf = TF{12};

T = zeros(length(N), length(A));

for ni = 1:length(N)
  x0 = GSLpp_get_startingpoint(tf.starting_point, N(ni));
  x_min = GSLpp_get_minimizer(tf.minimizer, N(ni));

  for ai = 1:length(A)
    results = GSLpp_minimize(A{ai}, struct, struct, ...
                             "extendedrosenbrock", struct("n", N(ni)), ...
                             struct("f", "precomp", "g", "fd", "H", "fd"), ...
                             "maxnumiter", ...
                             struct("n", 10), ...
                             x0, 0, true);
    T(ni, ai) = results.time;
  endfor
endfor

for j = 1:length(A_sets)
  GSLpp_newplot();
  plot(N, T(:, A_sets{j}), "linewidth", 6);
  xlabel("n");
  ylabel("time per iteration (microseconds)");
  legend(A_titles(A_sets{j}), "location", "northwest");
  legend("boxon");

  print([ "dimension_scaling_test", num2str(j), ".ps" ], "-landscape", "-dashed", "-FArial:23");
  close;
endfor
